package com.jy.appmarket.download;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 类说明：
 * 
 * @author Baker.li
 * @date 2014年5月19日
 * @version 1.0
 */

public class DownloadItem implements Parcelable {
	/** basic download task properties */
	private long _id;
	private String id;
	private String dlUrl;
	private String name;
	private int status;
	private long createTime;
	private long lastModification;
	private long downloadedSize;
	private long totalSize;
	private int retryCount;

	/** apk task properties */
	private String pkgName;
	private String versionName;
	private int versionCode;
	private String md5;
	private boolean autoInstall;

	/** other download properties */
	private String iconUrl;
	private String source;
	private int priority;
	private boolean shouldRemove;
	private boolean hidden;
	private transient long speed = 0; // add by toby

	// 增加字段，请补充相关字段到该赋值函数中
	public void assignValue(DownloadItem di) {
		_id = di._id;
		id = di.id;
		dlUrl = di.dlUrl;
		name = di.name;
		status = di.status;
		createTime = di.createTime;
		lastModification = di.lastModification;
		downloadedSize = di.downloadedSize;
		totalSize = di.totalSize;
		retryCount = di.retryCount;

		/** apk task properties */
		pkgName = di.pkgName;
		versionName = di.versionName;
		versionCode = di.versionCode;
		autoInstall = di.autoInstall;

		/** other download properties */
		iconUrl = di.iconUrl;
		source = di.source;
		priority = di.priority;
		shouldRemove = di.shouldRemove;
		hidden = di.hidden;
		speed = di.speed;
	}

	public long getSpeed() {
		return speed;
	}

	public void setSpeed(long s) {
		speed = s;
	}

	public long get_id() {
		return _id;
	}

	public void set_id(long _id) {
		this._id = _id;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDlUrl() {
		return dlUrl;
	}

	public void setDlUrl(String dlUrl) {
		this.dlUrl = dlUrl;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

	public long getLastModification() {
		return lastModification;
	}

	public void setLastModification(long lastModification) {
		this.lastModification = lastModification;
	}

	public long getDownloadedSize() {
		return downloadedSize;
	}

	public void setDownloadedSize(long downloadedSize) {
		this.downloadedSize = downloadedSize;
	}

	public long getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(long totalSize) {
		this.totalSize = totalSize;
	}

	public int getRetryCount() {
		return retryCount;
	}

	public void setRetryCount(int retryCount) {
		this.retryCount = retryCount;
	}

	public String getPkgName() {
		return pkgName;
	}

	public void setPkgName(String pkgName) {
		this.pkgName = pkgName;
	}

	public String getVersionName() {
		return versionName;
	}

	public void setVersionName(String versionName) {
		this.versionName = versionName;
	}

	public int getVersionCode() {
		return versionCode;
	}

	public void setVersionCode(int versionCode) {
		this.versionCode = versionCode;
	}

	public String getMd5() {
		return md5;
	}

	public void setMd5(String md5) {
		this.md5 = md5;
	}

	public boolean getAutoInstall() {
		return autoInstall;
	}

	public void setAutoInstall(boolean autoInstall) {
		this.autoInstall = autoInstall;
	}

	public String getIconUrl() {
		return iconUrl;
	}

	public void setIconUrl(String iconUrl) {
		this.iconUrl = iconUrl;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public boolean isShouldRemove() {
		return shouldRemove;
	}

	public void setShouldRemove(boolean shouldRemove) {
		this.shouldRemove = shouldRemove;
	}

	public boolean isHidden() {
		return hidden;
	}

	public void setHidden(boolean hidden) {
		this.hidden = hidden;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {

		dest.writeLong(_id);
		dest.writeString(id);
		dest.writeString(dlUrl);
		dest.writeString(name);
		dest.writeInt(status);

		dest.writeLong(createTime);
		dest.writeLong(lastModification);
		dest.writeLong(downloadedSize);
		dest.writeLong(totalSize);
		dest.writeInt(retryCount);

		dest.writeString(pkgName);
		dest.writeString(versionName);
		dest.writeInt(versionCode);
		if (autoInstall) {
			dest.writeInt(1);
		} else {
			dest.writeInt(0);
		}

		dest.writeString(iconUrl);
		dest.writeString(source);

		dest.writeInt(priority);
		if (shouldRemove) {
			dest.writeInt(1);
		} else {
			dest.writeInt(0);
		}

		if (hidden) {
			dest.writeInt(1);
		} else {
			dest.writeInt(0);
		}
	}

	public static final Parcelable.Creator<DownloadItem> CREATOR = new Parcelable.Creator<DownloadItem>() {
		@Override
		public DownloadItem createFromParcel(Parcel source) {
			DownloadItem dlItem = new DownloadItem();
			dlItem.set_id(source.readLong());
			dlItem.setId(source.readString());
			dlItem.setDlUrl(source.readString());
			dlItem.setName(source.readString());
			dlItem.setStatus(source.readInt());

			dlItem.setCreateTime(source.readLong());
			dlItem.setLastModification(source.readLong());

			dlItem.setDownloadedSize(source.readLong());
			dlItem.setTotalSize(source.readLong());
			dlItem.setRetryCount(source.readInt());

			dlItem.setPkgName(source.readString());
			dlItem.setVersionName(source.readString());
			dlItem.setVersionCode(source.readInt());

			if (source.readInt() == 1) {
				dlItem.setAutoInstall(true);
			} else {
				dlItem.setAutoInstall(false);
			}
			dlItem.setIconUrl(source.readString());
			dlItem.setSource(source.readString());

			dlItem.setPriority(source.readInt());
			if (source.readInt() == 1) {
				dlItem.setShouldRemove(true);
			} else {
				dlItem.setShouldRemove(false);
			}
			if (source.readInt() == 1) {
				dlItem.setHidden(true);
			} else {
				dlItem.setHidden(false);
			}
			return dlItem;
		}

		@Override
		public DownloadItem[] newArray(int size) {
			return new DownloadItem[size];
		}
	};
}